package com.shioirikukuri.mapper;

import com.shioirikukuri.entity.CouponType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CouponTypeMapper {
	// 插入一条优惠券类型记录
	@Insert("INSERT INTO coupon_type (name, description, type, value, effective_days, created_at, updated_at) " +
			"VALUES (#{name}, #{description}, #{type}, #{value}, #{effectiveDays}, NOW(), NOW())")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	void insertCouponType(CouponType couponType);

	// 根据ID查询优惠券类型
	@Select("SELECT * FROM coupon_type WHERE id = #{id}")
	CouponType selectCouponTypeById(Long id);

	// 查询所有优惠券类型
	@Select("SELECT * FROM coupon_type")
	List<CouponType> selectAllCouponTypes();

	// 更新优惠券类型信息
	@Update("UPDATE coupon_type SET name = #{name}, description = #{description}, type = #{type}, " +
			"value = #{value}, effective_days = #{effectiveDays}, updated_at = NOW() WHERE id = #{id}")
	void updateCouponType(CouponType couponType);

	// 根据ID删除优惠券类型
	@Delete("DELETE FROM coupon_type WHERE id = #{id}")
	void deleteCouponTypeById(Long id);
}
